import { useState } from "react";

function usePagination(config = {}) {
  let {
    cur = 1,
    size = 5,
    position = ["bottomRight"],
    showSizeChanger = true,
    pageSizeOptions = [5, 10, 15, 20],
    showQuickJumper = true,
  } = config;

  const [current, setCurrent] = useState(cur);
  const [pageSize, setPageSize] = useState(size);

  return {
    position,
    pageSize,
    current,
    showSizeChanger,
    pageSizeOptions,
    showQuickJumper,
    showTotal: (total) => {
      return <span>共有{total}条</span>;
    },
    onChange: (page, pageSize) => {
      setCurrent(page);
      setPageSize(pageSize);
    },
  };
}

export default usePagination;
